Page({
  data: {
    formData: {
      petName: '',
      petType: '',
      appointmentDate: '',
      appointmentTime: '',
      symptoms: ''
    }
  },
  onInput(e) {
    const { field } = e.currentTarget.dataset;
    this.setData({
      [`formData.${field}`]: e.detail.value
    });
  },
  submitForm() {
    console.log('预约信息:', this.data.formData);
    // 这里添加提交预约信息的逻辑
    wx.showToast({
      title: '预约成功',
      icon: 'success',
      duration: 2000
    });
  },
  submitForm() {
    const { petName, petType, appointmentDate, appointmentTime, symptoms } = this.data.formData;
    
    wx.request({
      url: 'http://127.0.0.1:3000/api/appointments',
      method: 'POST',
      data: {
        petName,
        petType,
        appointmentDate,
        appointmentTime,
        symptoms
      },
      success: (res) => {
        if (res.statusCode === 201) {
          console.log('预约成功:', res.data);
          wx.showToast({
            title: '预约成功',
            icon: 'success',
            duration: 2000
          });
        } else {
          console.error('预约失败:', res.data);
          wx.showToast({
            title: '预约失败',
            icon: 'none',
            duration: 2000
          });
        }
      },
      fail: (err) => {
        console.error('请求失败:', err);
        wx.showToast({
          title: '请求失败',
          icon: 'none',
          duration: 2000
        });
      }
    });
  }
})